---
category: Random
created: '2020-07-28'
title: Generate a random string using Node crypto module
updated: '2021-10-13'
---

**JavaScript version**

```js randomStr.js
const randomStr = () => require('crypto').randomBytes(32).toString('hex');
```

**TypeScript version**

```ts randomStr.ts
const randomStr = (): string => require('crypto').randomBytes(32).toString('hex');
```
